home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Jugar con las fuentes / WarpText / WarpText.cs next >
Encoding:
Text File  |  2002-05-12  |  1.7 KB  |  55 lines

  1. //---------------------------------------
  2. // WarpText.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class WarpText: FontMenuForm
  10. {
  11.      int iWarpMode = 0;
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new WarpText());
  16.      }
  17.      public WarpText()
  18.      {
  19.           Text = "Torcer texto - " + (WarpMode) iWarpMode;
  20.           Menu.MenuItems.Add("&Cambiar!", 
  21.                                    new EventHandler(MenuToggleOnClick));
  22.           strText = "TORCER";
  23.           font = new Font("Arial Black", 24);
  24.      }
  25.      void MenuToggleOnClick(object obj, EventArgs ea)
  26.      {
  27.           iWarpMode ^= 1;
  28.           Text = "Torcer texto - " + (WarpMode) iWarpMode;
  29.           Invalidate();
  30.      }
  31.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  32.      {
  33.           GraphicsPath path = new GraphicsPath();
  34.  
  35.                // A±adir texto al trazado.
  36.  
  37.           path.AddString(strText, font.FontFamily, (int) font.Style,
  38.                          100, new PointF(0, 0), new StringFormat());
  39.  
  40.                // Torcer el trazado.
  41.  
  42.           RectangleF rectfBounds = path.GetBounds();
  43.           PointF[]   aptfDest    = { new PointF(cx / 3, 0),
  44.                                      new PointF(2 * cx / 3, 0),
  45.                                      new PointF(0, cy),
  46.                                      new PointF(cx, cy) };
  47.  
  48.           path.Warp(aptfDest, rectfBounds, new Matrix(), 
  49.                     (WarpMode) iWarpMode);
  50.  
  51.                // Llenar el trazado.
  52.  
  53.           grfx.FillPath(new SolidBrush(clr), path);
  54.      }
  55. }